import {Request, Login} from "../../../utils/request.js";
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    
  },
  /**
   * 获取搜索输入框对象id
   */
  _bindinput:function(param){
    this.searchid = param.detail.value;
  },
  /**
   * 确定搜索内容
   */
  _bindtap:function(){
    if(app.globalData.loginCode == -1){
      if(app.globalData.loginCode == -1){
        //用户未注册 提示跳转注册页面
        new Login().LoginDown();
        return;
      }
    }
    if(this.searchid == undefined || this.searchid == null || this.searchid == '' ){
      new Request().showToast('请输入对象UID','error');
      return;
    }

    let arr = this.searchid.split('');
    if(arr[0] == 'u'){
      new Request().showToast('区分大写UID','error');
      return;
    }
    if(arr[0] != 'U'){
      new Request().showToast('输入有误UID','error');
      return;
    }
    this.searchid = this.searchid.slice(1);
    new Request('search/Search_Friend_Id/SearchId').request(
      () => {
        return {
          openid: app.globalData.openid,
          userid: app.globalData.userid,
          search_id: this.searchid,//对象id
        }
      },
      (res) => {
        if(res.data.code == 0){
          new Request().showToast(res.data.msg);
          return;
        }
        let url =   wx.getStorageSync("config");
        let reg = new RegExp("女");
        res.data.data.map(function(e){
          e.SQLhome     = e.city;
          e.name        = e.nichen;
          e.SQLposition = e.job;
          e.SQLheight   = e.hei;
          e.userimage   = url.service.host + e.avatar;
          e.SQLsex      = reg.test(e.gender);
          if(e.text == '' || e.text == undefined){
            e.text = 'TA还没有独白哟………';
          }
        });
        console.log(res.data.data);
        this.setData({
          userinfo: res.data.data,
          userStatus: true,
        });
    });
    return;
  },
  /**
   * 确定选中，并且返回上一页面
   */
  _bindtap_queding:function(){
    const eventChannel = this.getOpenerEventChannel();
    let object_info = {
      object_id: this.data.userinfo[0].id,
      object_img: this.data.userinfo[0].userimage,
    };
    eventChannel.emit('object_info', object_info); //回传对象id给上页面
    wx.navigateBack({
      delta: 1,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    // const eventChannel = this.getOpenerEventChannel()
    // eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'}); //回传对象id给上页面
    // eventChannel.emit('someEvent', {data: 'test'});
    // console.log(res)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    // const eventChannel = this.getOpenerEventChannel()
    // eventChannel.emit('acceptDataFromOpenedPage', {data: 'test'}); //回传对象id给上页面
    // eventChannel.emit('someEvent', {data: 'test'});
    // console.log(res)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})